package com.chenyaowei.web.controller.marketing;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.marketing.domain.CywSpuDiscount;
import com.chenyaowei.marketing.service.ICywSpuDiscountService;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.common.core.page.TableDataInfo;

/**
 * 商品折扣Controller
 *
 * @author 陈耀威
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/marketing/spuDiscount")
public class CywSpuDiscountController extends BaseController
{
    @Autowired
    private ICywSpuDiscountService cywSpuDiscountService;

    /**
     * 查询商品折扣列表
     */
    @PreAuthorize("@ss.hasPermi('product:spuDiscount:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywSpuDiscount cywSpuDiscount)
    {
        startPage();
        List<CywSpuDiscount> list = cywSpuDiscountService.selectCywSpuDiscountList(cywSpuDiscount);
        return getDataTable(list);
    }

    /**
     * 导出商品折扣列表
     */
    @PreAuthorize("@ss.hasPermi('product:spuDiscount:export')")
    @Log(title = "商品折扣", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywSpuDiscount cywSpuDiscount)
    {
        List<CywSpuDiscount> list = cywSpuDiscountService.selectCywSpuDiscountList(cywSpuDiscount);
        ExcelUtil<CywSpuDiscount> util = new ExcelUtil<CywSpuDiscount>(CywSpuDiscount.class);
        util.exportExcel(response, list, "商品折扣数据");
    }

    /**
     * 获取商品折扣详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:spuDiscount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywSpuDiscountService.selectCywSpuDiscountById(id));
    }

    /**
     * 新增商品折扣
     */
    @PreAuthorize("@ss.hasPermi('product:spuDiscount:add')")
    @Log(title = "商品折扣", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywSpuDiscount cywSpuDiscount)
    {
        return toAjax(cywSpuDiscountService.insertCywSpuDiscount(cywSpuDiscount));
    }

    /**
     * 修改商品折扣
     */
    @PreAuthorize("@ss.hasPermi('product:spuDiscount:edit')")
    @Log(title = "商品折扣", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywSpuDiscount cywSpuDiscount)
    {
        return toAjax(cywSpuDiscountService.updateCywSpuDiscount(cywSpuDiscount));
    }

    /**
     * 删除商品折扣
     */
    @PreAuthorize("@ss.hasPermi('product:spuDiscount:remove')")
    @Log(title = "商品折扣", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywSpuDiscountService.deleteCywSpuDiscountByIds(ids));
    }
}
